/**
 * 
 */
package cc.dogtailflower.framework.basedao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import javax.sql.DataSource;

import cc.dogtailflower.framework.resultsetmapper.ResultSetMapper;


/**
 * 基本操作接口
 * @author cc
 *
 */
public interface JdbcOperation<T> {

	/*
	 * update delete
	 */
	public int execute(String sql,Object[] params) throws SQLException;
	
	public int execute(String sql) throws SQLException;
	
	/*
	 * select
	 */
	public List<T> queryForResultSet(String sql,Object[] params,ResultSetMapper<T> mapper) throws SQLException;
	
	public List<T> queryForResultSet(String sql,ResultSetMapper<T> mapper) throws SQLException;
	
	/*
	 * select 返回集合
	 */
	public List<T> queryForBean(String sql,Object[] params,ResultSetMapper<T> mapper,Class<?> targetClass) throws SQLException;
	
	public List<T> queryForBean(String sql,ResultSetMapper<T> mapper,Class<?> targetClass) throws SQLException;
	
	/*
	 * 统计单列记录数
	 */
	public int queryForInt(String sql,Object[] params) throws SQLException;
	
	public int queryForInt(String sql) throws SQLException;
	
	/*
	 * 释放Connection
	 */
	public void free(Connection x);
	
	/*
	 * 释放Statement
	 */
	public void free(Statement x);
	
	/*
	 * 释放PreparedStatement
	 */
	public void free(PreparedStatement x);
	
	/*
	 * 释放ResultSet
	 */
	public void free(ResultSet x);
	
	/*
	 * 设置数据源
	 */
	public void setDataSource(DataSource dataSource);
	
	/*
	 * 获取数据库连接
	 */
	public Connection getConnection();
	
	/*
	 * 获取数据库连接，事务
	 */
	public Connection getConnection(boolean autoCommit);
}
